package Singleton;

// 单例类一般不希望被继承，否则子类可能创建多个实例破坏单例语义
public final class EagerSingleton {
    private final static EagerSingleton instance = new EagerSingleton();
    private EagerSingleton(){
        // 防止别人反射强制调用
        if(instance != null) {
            throw new RuntimeException("Use getInstance() method to get singleton instance.");
        }
    }

    public static EagerSingleton getInstance() {
        return instance;
    }
}
